<?php

namespace app\app\controller;


use app\app\model\ProjectSafeMeetModel;
use app\app\model\ProjectModel;
use app\BaseController;
use app\Request;

class ProjectSafeMeet extends BaseController
{

    public function index(Request $request)
    {

        $page_size = input('pageSize', '20');
        $where = '1=1';

        if (!empty($data['start_time']) && !empty($data['end_time'])) {
            $where .= " AND a.hy_time BETWEEN '" . $data['start_time'] . "' AND  '" . $data['end_time'] . "'";
        } else {
            if (!empty($data['start_time'])) $where .= " AND a.hy_time > '" . $data['start_time'] . "'";
            if (!empty($data['end_time'])) $where .= " AND a.hy_time < '" . $data['end_time'] . "'";
        }

        $list = ProjectSafeMeetModel::alias('a')
            ->field('a.*,b.file_name as hyjy_name,b.file_path as hyjy_file_path,c.file_name as hycl_name,c.file_path as hycl_file_path')
            ->leftjoin('sys_file_info b', 'b.file_id = a.hyjy_file_id')
            ->leftjoin('sys_file_info c', 'c.file_id = a.hycl_file_id')
            ->where($where)->paginate($page_size);

        $this->success('success', $list);
    }


    public function detail()
    {
        $id = input('id', '20');
        $list = ProjectSafeMeetModel::alias('a')
            ->field('a.*,b.file_name as hyjy_name,b.file_path as hyjy_file_path,c.file_name as hycl_name,c.file_path as hycl_file_path')
            ->leftjoin('sys_file_info b', 'b.file_id = a.hyjy_file_id')
            ->leftjoin('sys_file_info c', 'c.file_id = a.hycl_file_id')->where('id', $id)->find();
        $this->success('success', $list);
    }


    public function add()
    {
        $data = $this->request->param();

        $project_info = ProjectModel::where('id', $data['project_id'])->find();
        $data['project_name'] = $project_info['project_name'];
        $res = ProjectSafeMeetModel::create($data);
        $this->success('success');
    }


    public function update()
    {
        $data = $this->request->param();
        $id = $data['id'];
        unset($data['id']);
        $res = ProjectSafeMeetModel::where('id', $id)->update($data);
        $this->success('success');
    }


}
